package com.exam.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherMapper {

//@Query(value = "select * from teacher", countQuery = "select count(*) from teacher")
    //查询所有教师信息
    @Select("select * from teacher")
    IPage<Teacher>  findAll(Page page);

//@Query(value = "select * from teacher")
    //查询所有教师信息
    @Select("select * from teacher")
    List<Teacher> findAll();

//@Query(value = "select * from teacher where teacherId = #{teacherId}")
    //根据教师ID查询教师信息
    @Select("select * from teacher where teacherId = #{teacherId}")
    Teacher findById(Integer teacherId);

//@Query(value = "delete from teacher where teacherId = #{teacherId}")
    //根据教师ID删除教师信息
    @Delete("delete from teacher where teacherId = #{teacherId}")
    int deleteById(Integer teacherId);

//@Query(value = "update teacher set teacherName = #{teacherName},sex = #{sex}," +
//                "tel = #{tel}, email = #{email},pwd = #{pwd},cardId = #{cardId}," +
//                "role = #{role},institute = #{institute},type = #{type} where teacherId = #{teacherId}")
    //根据教师ID更新教师信息
    @Update("update teacher set teacherName = #{teacherName},sex = #{sex}," +
            "tel = #{tel}, email = #{email},pwd = #{pwd},card_id = #{cardId}," +
            "role = #{role},institute = #{institute},type = #{type} where teacherId = #{teacherId}")
    int update(Teacher teacher);

//@Query(value = "insert into teacher(teacherName,sex,tel,email,pwd,cardId,role,type,institute) " +
//                "values(#{teacherName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role},#{type},#{institute})")
    //插入教师信息
    @Options(useGeneratedKeys = true,keyProperty = "teacherId")
    @Insert("insert into teacher(teacherName,sex,tel,email,pwd,card_id,role,type,institute) " +
            "values(#{teacherName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role},#{type},#{institute})")
    int add(Teacher teacher);


    //根据电话号码,身份证号,邮箱号查询教师信息
    @Select("select * from teacher where tel = #{tel} and card_id = #{cardId} and email = #{email}")
    List<Teacher> findByTelAndCardIdAndEmail(Teacher teacher);

    //根据教师全部信息查找具体老师
    @Select("select * from teacher where teacherName = #{teacherName} and sex = #{sex} and tel = #{tel} and " +
            " institute = #{institute} and type = #{type} and type = #{type} and card_id = #{cardId}")
    List<Teacher> findByAllTeacherData(Teacher teacher);
}
